package cn.com.majiang.service.impl;

import cn.com.majiang.dao.ResourcesDao;
import cn.com.majiang.domain.Resources;
import cn.com.majiang.service.IResourcesService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by jiangyanxin on 2017/5/28.
 */
@Service
public class ResourcesServiceImpl implements IResourcesService {
    Logger logger = LoggerFactory.getLogger(ResourcesServiceImpl.class);
    @Autowired
    ResourcesDao resourcesDao;
    @Override
    public List<Map<String,String>> getResourcesByPowerId(Integer powerId) {
        List<Map<String,String>> list = new ArrayList<>();
        Resources resources =  resourcesDao.getResourcesByPowerId(powerId);
        if(resources != null){
            String resoucesurl = resources.getResourceurl();
            String resourcesname = resources.getResourcename();
            if(StringUtils.isNotBlank(resoucesurl) && StringUtils.isNotBlank(resourcesname)){
                List<String> menuurls = Arrays.asList(resoucesurl.split(","));
                List<String> menunames = Arrays.asList(resourcesname.split(","));
                for(int i=0;i<menuurls.size();i++){
                    Map<String,String> map = new HashMap<>();
                    map.put("url",menuurls.get(i));
                    map.put("menuid",i+"");
                    map.put("menuname",menunames.get(i));
                    list.add(map);
                }
            }
        }
        return list;
    }
}
